#include "../corelib/network/ringbuffer.hh"
#include "unittest/unittest.hh"
#include <cstring>
#include <cstdlib>
#include <chrono>

using namespace kratos::network;

FIXTURE_BEGIN(Ringbuffer)

CASE(TestPush1) {
    char c = 0;
    Ringbuffer<char, 8> rb;
    ASSERT_TRUE(8 == rb.push("12345678", 8));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
}

CASE(TestPush2) {
    char c = 0;
    Ringbuffer<char, 8> rb;
    ASSERT_TRUE(2 == rb.push("12", 2));
    ASSERT_TRUE(8 == rb.push("12345678", 8));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
}

CASE(TestPush3) {
    char c = 0;
    Ringbuffer<char, 2> rb;
    ASSERT_TRUE(8 == rb.push("12345678", 8));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
    ASSERT_TRUE(rb.read(c));
}

FIXTURE_END(Ringbuffer)
